<?php if (!defined('insite')) die("no access"); 
if (defined('insite') && adm_check($_SESSION["user"])>=1)
{
	require "opt.php";
	if ($_REQUEST["clear_m"])
	{
		$faqhandle = opendir("_dat/cach");
		$goz = "_dat/cach/";
		while (false !== ($file = readdir($faqhandle))) 
		{ 
			if ($file != "." && $file != ".." && $file!=".htaccess") 
			{
				@unlink($goz.$file);
			} 			
		}
		echo "<div align='center' class='succes'>Done!</div>";
	}
	?>
	<table width='90%'  class='tableMain' align='center' vAlign='top' border='0'>
	<tr>
		<td align="center"><?=mm_manager_ttl?></td>
		<td align="center">
		<form name="typedit" method="post" action="">
		<select name="typemanage" class='combx' onChange='document.typedit.submit();'>
		<option><?=mm_manager_type0?></option>
		<option value="main" ><?=mm_manager_type1?></option>
		<option value="user" ><?=mm_manager_type2?></option>
		</select>
		
		</form>
		</td>
	<tr>
	</table>	
	<?
	if (isset($_POST["typemanage"]))
	{
		switch ($_POST["typemanage"])
		{
			case "main":$_SESSION["typemanage"]="pm";break;
			case "user":$_SESSION["typemanage"]="upm";break;
			default: die("wrong choise!");
		}
	}
	else
	{
		if (strlen($_SESSION["typemanage"])<2){$_SESSION["typemanage"]="pm";}
	}
	$cfil=substr($_SESSION["typemanage"],0,3);

	$pmfile = @file("_dat/".$cfil.".dat");
	$btnval=" name='addmod' value='".mm_manager_btn1."'";$modname[0]="";$modname[1]="";
		if($_REQUEST["addmod"])
		{
				$modnamf=substr(validate($_POST["mname"]),0,10);
				$modopt = substr(checknum($_POST["opttype"]),0,1);
				$stringw=$modnamf."||".$modopt.chr(13).chr(10);
				$fh = fopen("_dat/".$cfil.".dat","a");
				fwrite($fh,$stringw);
				fclose($fh);header("location:".$config["siteaddress"]."/index.php?p=usercp&ss=mmodul");
		}
		if (isset($_GET["edit"]))
		{
			$p=substr(checknum($_GET["pos"]),0,3);
			$btnval=" name='okmod' value='".mm_manager_btn."'";
			if ($_GET["edit"]==1){if(strlen($p)<1){$modname[0]="";$modname[1]="";}else{$modname = explode("||",$pmfile[$p]);}}
			elseif($_GET["edit"]==0)
			{
				$p=substr(checknum($_GET["pos"]),0,3);
				$mcount= count($pmfile);
				unset($pmfile[$p]);
				$fonw = fopen("_dat/".$cfil.".dat","w");
				for ($i=0; $i<$mcount;$i++)
				{
					if (!$pmfile[$i]){ $i++; fwrite($fonw,$pmfile[$i]);}
					else {fwrite($fonw,$pmfile[$i]);}
				}
				fclose($fonw);
				$btnval=" name='addmod' value='".mm_manager_btn1."'";$modname[0]="";$modname[1]="";
				header("location:".$config["siteaddress"]."/index.php?p=usercp&ss=mmodul");
			}else{$btnval=" name='addmod' value='".mm_manager_btn1."'";}
			if ($_REQUEST["okmod"])
				{
					$modnamf=substr(validate($_POST["mname"]),0,10);
					$modopt = substr(checknum($_POST["opttype"]),0,1);
					$pmfile[$p]=$modnamf."||".$modopt.chr(13).chr(10);		
					$fh = fopen("_dat/".$cfil.".dat","w");
					for ($i=0; $i<count($pmfile);$i++)
					{fwrite($fh,$pmfile[$i]);}
					fclose($fh);
					$btnval=" name='addmod' value='".mm_manager_btn1."'";$modname[0]="";$modname[1]="";
					header("location: ".$config["siteaddress"]."/index.php?p=usercp&ss=mmodul");
				}
		}?>

		
	<table width='90%'  class='tableMain' align='center' vAlign='top' border='0'>
		    <tr class='trstyle'>
						<td class='zagstyle' colspan='3'>
							<?
								if ($_SESSION["typemanage"]=="pm") echo mm_manager_type1;
								elseif ($_SESSION["typemanage"]=="upm") echo mm_manager_type2;
								else echo mm_manager_title;
								
							?></td>				
		    </tr>
			<tr>
				<td class='zagmain'><?=mm_manager_mod?></td>
				<td class='zagmain'><?=mm_manager_opt?></td>
				<td class='zagmain'><?=mm_manager_opto?></td>
			</tr>
		<?	foreach ($pmfile as $n=>$s)
			{
				$showmod = explode("||",$s);
				echo "<tr align='center'>
						<td width='30%'>$showmod[0]</td><td width='30%'>".mod_status ($showmod[1])."</td><td width='30%'><a href='".$config["siteaddress"]."/index.php?p=usercp&ss=mmodul&edit=1&pos=$n'><img src='imgs/edit.png' title='edit' border='0'></a><a href='".$config["siteaddress"]."/index.php?p=usercp&ss=mmodul&edit=0&pos=$n'><img src='imgs/delete.png' title='delete' border='0'></a></td>
					  </tr>";
			}
			?>
			</table><bR>	
					<table width='80%'  class='tableMain' align='center' vAlign='top' border='0'>
						<tr class='trstyle'>
						<td class='zagstyle' ><?=dl_manager_bt2?></td>				
					</tr>
					<tr>
					<td align='center'>
					<form method='POST' action=''>
					<table width='80%'  align='center' vAlign='top' border='0'>
					<tr align='center'>
						<td><?=mm_manager_mod?></td><td><?=mm_manager_opt?></td>
					</tr>
					<tr align='center'>
						<td><input type='text' class='texbx' name='mname' maxlength='10' value='<?=$modname[0]?>'></td>
						<td>
							<select name='opttype' class='combx'>
							<option value='0'<? if ($modname[1]==0){echo "SELECTED";}?>>Off</option>
							<option value='1'<? if ($modname[1]==1){echo "SELECTED";}?>>On</option>
							</select>
						</td>
					</tr>
					<tr align='center'>
						<td colspan='2'><br><input type='submit' class='t-button' <?=$btnval?>></td>
					</tr>
					</table>
					</form></td>
					</tr></table><hr>
					<div align="center"><form method="POST" action=""><input type="submit" name="clear_m" value="<?=mm_modul_clear?>" class="t-button"></form></div>
					<?$pracces=0;
					
}